package com.supermap.util.base;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.supermap.pisaclient.R;
import com.supermap.util.imageloader.ImageLoader;

import java.util.List;

/**
 * Copyright (C) 2017 北京超图软件股份有限公司 版权所有
 * <p>
 * 功能描述：所有banner的基类 作者：李会林
 * <p>
 * 修改人： 修改描述： 修改日期
 */
public class CommonBannerAdapter extends PagerAdapter {
    private List<String> mData;
    private Context mContext;

    /**
     * @param context
     * @param list
     */
    public CommonBannerAdapter(Context context, List<String> list) {
        mContext = context;
        mData = list;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getCount() {
        if (mData == null) {
            return 0;
        } else if (mData.size() == 1) {
            return mData.size();
        } else {
            return Integer.MAX_VALUE;
        }
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = View.inflate(mContext, R.layout.layout_user_banner, null);
        ImageView image = (ImageView) view.findViewById(R.id.user_banner_image);
        ImageLoader.IamgeLoading(mContext, mData.get(position % mData.size()), image);
        container.addView(view);
        return view;
    }
}
